<?php
namespace app\monitor\controller;

use think\Controller;
use app\monitor\model\Website as Site;

class Website extends Controller
{
    public function index()
    {
        return $this->fetch();
    }
    
    public function add() {
        if(request()->isPost()) {
            $website = Websites::create(request()->param());
            $this->success($website->name.'添加成功');
            //dump(request()->param());
        }
        return $this->fetch();
    }

    public function category() 
    {   $webInfo = Websites::all()[0]->toArray();
        $html = file_get_contents($webInfo['url']);
        $htmlDom = new \HtmlParser\ParserDom($html);
        $categorys = $htmlDom->find('#mainNav li h4 a');
        foreach ($categorys as $category) {
            $categoryInfo = [$category->getPlainText(),$category->href];
            $categoryInfos[] = $categoryInfo;
        }
        dump($categoryInfos);
    }
    public function test()
    {
       $site = new Site('http://jsj.wuning.gov.cn/');
    //    dump($site->fetchCategoryUrl());
    //    echo '<br>';
       dump($site->getCategoryInfo());
    }

}